package cn.dankal.flyaudio.pop;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import cn.dankal.basiclib.util.ToastUtils;
import cn.dankal.flyaudio.R;
import cn.dankal.flyaudio.configs.PayConfigs;
import razerdp.basepopup.BasePopupWindow;

public class AfterSalesPop extends BasePopupWindow implements View.OnClickListener {

    private TextView pickMoneyView;
    private TextView pickMoneyAndStoreView;
    private TextView applyView;
    private EditText inputView;


    public AfterSalesPop(Context context) {
        super(context);
    }


    @Override
    public View onCreateContentView() {

        return createPopupById(R.layout.pop_after_sales);
    }


    @Override
    public void onViewCreated(View contentView) {
        super.onViewCreated(contentView);
        pickMoneyAndStoreView = findViewById(R.id.tv_pick_store_and_money);
        pickMoneyView = findViewById(R.id.tv_pick_money);
        applyView = findViewById(R.id.tv_apply);
        inputView = findViewById(R.id.et_reason);
        pickMoneyAndStoreView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pickMoneyAndStoreView.setSelected(true);
                pickMoneyView.setSelected(false);
            }
        });
        pickMoneyView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pickMoneyAndStoreView.setSelected(false);
                pickMoneyView.setSelected(true);
            }
        });
        applyView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String reason = inputView.getText().toString().trim();
                if (TextUtils.isEmpty(reason)) {
                    ToastUtils.showShort("请输入售后原因");
                    return;
                }
                if (!pickMoneyView.isSelected() && !pickMoneyAndStoreView.isSelected()) {
                    ToastUtils.showShort("请选择售后方式");
                    return;
                }
                if (listener != null) {
                    dismiss();
                    listener.doApply(reason, pickMoneyView.isSelected());
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
    }

    private DoApplyListener listener;

    public AfterSalesPop setDoApplyListener(DoApplyListener listener) {
        this.listener = listener;
        return this;
    }

    public interface DoApplyListener {
        void doApply(String reason, boolean isRefundOnlyMoney);
    }
}
